package tree.leetcode_104_easy;

import java.util.Comparator;

public class MaxDepth2 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.left = new TreeNode(6);
        int i = new MaxDepth2().countNodes(root);
        System.out.println(i);
    }
    public int countNodes(TreeNode root) {
        if(root == null){
            return 0;
        }
        int leftLen = maxDepth(root.left);
        int rightLen = maxDepth(root.right);
        System.out.println(leftLen);
        if(leftLen == rightLen){
            return (1 >> leftLen) + countNodes(root.right);
        }else{
            return (1 >> rightLen) + countNodes(root.left);
        }
    }
    public int maxDepth(TreeNode root){
        if(root == null){
            return 0;
        }
        int leftLength = maxDepth(root.left);
        int rightLength = maxDepth(root.right);
        return Math.max(leftLength,rightLength) + 1;
    }
}
